﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Vlc.DotNet.Wpf;

namespace Audio2
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();

        //初始化配置，指定引用库
        myControl.MediaPlayer.VlcLibDirectoryNeeded += OnVlcControlNeedsLibDirectory;
        myControl.MediaPlayer.EndInit();
    }
    private void OnVlcControlNeedsLibDirectory(object sender, Vlc.DotNet.Forms.VlcLibDirectoryNeededEventArgs e)
    {
        var currentAssembly = Assembly.GetEntryAssembly();
        var currentDirectory = new FileInfo(currentAssembly.Location).DirectoryName;
        if (currentDirectory == null)
            return;
        if (AssemblyName.GetAssemblyName(currentAssembly.Location).ProcessorArchitecture == ProcessorArchitecture.X86)
            e.VlcLibDirectory = new DirectoryInfo(System.IO.Path.Combine(currentDirectory, @"..\..\..\lib\x86\"));
        else
            e.VlcLibDirectory = new DirectoryInfo(System.IO.Path.Combine(currentDirectory, @"..\..\..\lib\x64\"));
    }
    private void OnPlayButtonClick(object sender, RoutedEventArgs e)
    {
        //播放网络视频
        //myControl.MediaPlayer.Play(new Uri("http://download.blender.org/peach/bigbuckbunny_movies/big_buck_bunny_480p_surround-fix.avi"));
        //播放FM广播失败
        myControl.MediaPlayer.Play(new Uri("http://ngcdn001.cnr.cn/live/zgzs48/index.m3u8"));

        ////播放本地视频
        //string filename = @"F:\MyDocument\视频\COOLUI理念篇.mp4";
        //myControl.MediaPlayer.Play(new FileInfo(filename));
    }
    private void OnForwardButtonClick(object sender, RoutedEventArgs e)
    {
        myControl.MediaPlayer.Rate = 2;
    }

    private void GetLength_Click(object sender, RoutedEventArgs e)
    {
        GetLength.Content = myControl.MediaPlayer.Length + " ms";
    }
    private void GetCurrentTime_Click(object sender, RoutedEventArgs e)
    {
        GetCurrentTime.Content = myControl.MediaPlayer.Time + " ms";
    }
    private void SetCurrentTime_Click(object sender, RoutedEventArgs e)
    {
        myControl.MediaPlayer.Time = 5000;
        SetCurrentTime.Content = myControl.MediaPlayer.Time + " ms";
    }
}
}
